<template>
  <a-card :bordered="false">
    <a-form-model :model="form" :label-col="{ span: 4 }" :wrapper-col="{ span: 16 }" @submit="handleSubmit">
      <a-form-model-item label="默认赠送积分">
        <a-input-number v-model="form.defaultPoints" :min="-1" />
        积分
      </a-form-model-item>
      <a-form-model-item label="积分价值定义">
        1元=
        <a-input-number v-model="form.pointsPrice" :min="-1" />
        积分
      </a-form-model-item>
      <a-form-model-item style="margin-left: 15%">
        <a-button
          type="primary"
          htmlType="submit"
          class="login-button"
          :loading="submitLoading"
          :disabled="submitLoading"
        >保存
        </a-button>
      </a-form-model-item>
    </a-form-model>
  </a-card>
</template>

<script>
import { getPoints, updatePoints } from '@/api/manage'

export default {
  name: 'IntegralList',
  data () {
    return {
      form: {
        defaultPoints: -1,
        pointsPrice: -1
      },
      submitLoading: false
    }
  },
  created () {
    getPoints().then(response => {
      this.form = response.data
    })
  },
  methods: {
    handleSubmit (e) {
      e.preventDefault()
      this.submitLoading = true
      updatePoints(this.form.defaultPoints, this.form.pointsPrice).then(() => {
        this.$message.success('保存成功')
      }).finally(() => {
        this.submitLoading = false
      })
    }
  }
}
</script>

<style scoped>

</style>
